import random
from multiprocessing import Process,Queue


def compute(q):
    '''计算100万个1到100之间的随机数的和'''
    total = sum([random.randint(1,100) for i in range(1000000)])
    q.put(total)

def main():
    q = Queue()
    processes = [Process(target=compute,args=(q,)) for _ in range(8)]
    for process in processes:
        process.start()

    for process in processes:
         process.join()

    result_list = []
    # 判断队列有没有东西，有东西就一直取，没有就退出
    while not q.empty():
        # get_nowait 取一个少一个
        result_list.append(q.get_nowait())
    print(result_list)


if __name__ == '__main__':
    main()

